package problems.onemax;

import ec.BitSolution;
import ec.ECFitnessEvaluator;
import ec.Solution;

public class OneMaxFitnessEvaluator extends ECFitnessEvaluator {

	private double _max_fitness = Double.NaN;
	
	public double getFitness(Solution solution) {
		BitSolution bit_solution = (BitSolution) solution;
		
		if ( Double.isNaN(_max_fitness)) {
			_max_fitness = bit_solution.getNumBits();
		}
		
		return bit_solution.getBitSet().cardinality();
	}

	public double getMaxFitness() {
		return _max_fitness;
	}

}
